<template>
	<view class="warp" style="padding: 30rpx; background-color: #FFFFFF;position: fixed;">
		<view class="kf-top " style="color: #333333;" v-if="!type">
			<text style="color: #999999;margin-left: 20rpx;">客服电话:</text>400-090-0880<text class="iconfont cmain ml30"
				@click="callphone('400-090-0880')">&#xe8b8;</text>
		</view>
		<view class="title" v-if="!type">
			留言
		</view>
		<view class="c66" style="width: 90%;">
			您好，如果客服不在线，请留言。如果没有留下您的联
			系方式，客服将无法和您联系。
		</view>
		<view name="content">

			<textarea placeholder="请详细填写反馈内容" class="uni-textarea-border mt30" v-model="text" trim="right"></textarea>
		</view>
		<view class="c66 mt30">
			留下一下信息,方便与您及时联系
		</view>
		<view class="item ">
			姓名:<input v-model="user_name" placeholder="(必填)" style="border: #FFFFFF;" />
		</view>
		<view class="item ">
			手机:<input v-model="mobile" maxlength="11" placeholder="(必填)" />
		</view>
		<button  @click="save">提交留言</button>
		<!-- 	<view class="tip mt20">
			上传图片
		</view>
		<view name="imgs" class="mt30 flex" style="justify-content: start;">
			<image v-for="(item,index) in imgArr" :src="item" style="width: 140rpx;height: 140rpx;margin-left: 30rpx;"
				mode="aspectFill"></image>
			<view class="iconfont" @click="uploadImg" style="font-size: 140rpx;color: #f0f0f0;margin-left: 30rpx;">
				&#xe60f;</view>
		</view> -->
		<!-- 	<view class="uni-button-group">
			<button type="primary" class="uni-button " style="background-color: #007AFF;border-radius: 40rpx;"
				@click="submit">提交反馈</button>
		</view> -->
	</view>
</template>

<script>
import { propose} from '../../../api/api.js'
	export default {
		data() {
			return {
				imgArr: [],
				text: "",
				userInfo: {},
				user_name: "",
				mobile: "",
				uploadUrl: "",
				type: 0
			}
		},
		onLoad(opt) {
			console.log('页面传参', opt)
			if (opt.type) {
				this.type = 1
			}
			this.userInfo = uni.getStorageSync('userInfo')
			this.uploadUrl = uni.getStorageSync('uploadUrl')
		},
		methods: {
			// 拨打电话
			callphone(e) {
				uni.makePhoneCall({
					phoneNumber: e
				});
			},
			save() {
				if (!this.text || !this.user_name || !this.mobile) return uni.showToast({
					title: "请完善后重试!",
					icon: "none"
				});
				let data = {
					content: this.text,
					user_name: this.user_name,
					mobile: this.mobile
				}
				console.log('tj', data)
				propose(data).then(res => {
					uni.showToast({
						title: res.msg
					})
					uni.navigateTo({
						url: "/pages/index/index"
					})
				})

			},
			uploadImg() {
				let that = this
				uni.chooseImage({
					success: (res) => {
						// 获取的格式是数组，多选会同时返回，单选只返回一项
						this.imgArr = res.tempFilePaths;
						// 若多选，需循环调用uni.uploadFile ，因微信小程序只支持单文件上传
						console.log(this.imgArr)

					}
				});
				// uni.chooseImage({
				// 	success(res) {
				// 		console.log(res)
				// 		that.imgArr = res.tempFilePaths;
				// 		upload(that.imgArr).then(res => {

				// 		})
				// 	}
				// })
			},
			/**
			 * 触发表单提交
			 */
			submit() {

				console.log('2222');
				uni.uploadFile({
					url: this.uploadUrl, //仅为示例，非真实的接口地址
					filePath: this.imgArr[0],
					name: 'file',
					// methods:'post',
					success: (res) => {
						// 根据接口具体返回格式   赋值具体对应url
						let path = JSON.parse(res.data)
						// 提交
						let data = {
							user_id: this.userInfo.id,
							text: this.text,
							images: path.data,
						}
						let sign = this.$util(data)
						if (!data.text || !data.user_id) {
							uni.showToast({
								title: '请完善信息再提交!',
								duration: 1000
							})
						} else {
							propose(sign).then(res => {
								if (res.msg == '发布成功') {
									uni.showToast({
										title: res.msg,
									})
									this.text = ''
									this.imgArr = []
								}


							})
						}
					}
				});

			},

		}
	}
</script>

<style scoped lang="less">
	.uni-container {
		padding: 15px;
	}

	.uni-input-border,
	.uni-textarea-border {
		width: 100%;
		font-size: 14px;
		color: #666;
		border: 1px #e5e5e5 solid;
		border-radius: 5px;
		box-sizing: border-box;
	}

	.uni-input-border {
		padding: 0 10px;
		height: 35px;
	}

	.uni-textarea-border {
		padding: 10px;
		height: 80px;
		width: 90%;
	}

	.uni-button-group {
		position: absolute;
		left: 50%;
		transform: translateX(-50%);
		width: 100%;
		margin-top: 50px;
		display: flex;
		justify-content: center;
		flex-direction: row;
	}

	.uni-button {
		width: 300px;
		padding: 12px 20px;
		font-size: 14px;
		line-height: 1;
	}

	.uni-container /deep/ .uni-file-picker__container {
		flex-direction: row;
	}

	.title {
		width: 100%;
		height: 180rpx;
		line-height: 180rpx;
		text-align: center;
		color: #5490FE;
	}

	.item {
		width: 88%;
		display: flex;
		padding: 20rpx 0;
		padding-left: 20rpx;
		justify-content: flex-start;
		align-items: flex-start;
		border: 1rpx solid #e5e5e5;
		margin-top: 20rpx;
	}
</style>
